include ../Module.cfg

ifndef MINIX_MODULE
	SUBDIRS += minix
endif

ifndef ISO9660_MODULE
	SUBDIRS += iso9660
endif

SUBDIRS += ext2

ARCHIVES := $(foreach ele, $(SUBDIRS), $(ele)/$(ele).tmp.o)
MYARCHIVES := $(foreach ele, $(SUBDIRS), $(COMP_BUILD_DIR)/$(COMPONENT)/$(ele).tmp.o)

ALLDIRS := $(foreach ele, $(SUBDIRS), $(PWD)/$(COMPONENT)/$(ele))
ALLBUILDDIRS := $(foreach ele, $(SUBDIRS), $(COMP_BUILD_DIR)/$(COMPONENT)/$(ele))

COBJS := $(patsubst %.c, %.o, $(wildcard *.c))
ASMOBJS := $(patsubst %.S, %.o, $(wildcard *.S))

OVERRIDING = YES

include $(ROOTDIR)/Rules.mk

vpath %.c $(PWD)/$(COMPONENT) $(ALLDIRS) 
vpath %.o $(COMP_BUILD_DIR)/$(COMPONENT)  
vpath %.det $(COMP_BUILD_DIR)/$(COMPONENT)

$(TARGET_LIB):	$(OBJS) $(ARCHIVES)
	@-rm -f $(TARGET_LIB).log
	@-cat $(COMP_BUILD_DIR)/$(COMPONENT)/*.log > $(TARGET_LIB).log
	@$(LD) $(LDFLAGS) -o $@ $(MYOBJS) $(MYARCHIVES) >> $(TARGET_LIB).log


.PHONY:	$(ARCHIVES)
$(ARCHIVES): $(SUBDIRS)

.PHONY: $(SUBDIRS)
$(SUBDIRS):
	@if [ ! -d $(COMP_BUILD_DIR)/$(COMPONENT)/$@ ]; then mkdir -p $(COMP_BUILD_DIR)/$(COMPONENT)/$@ ; fi
	@make $(MKFLAGS) $@ SUBCOMPONENT=$@

clean:
	@rm -f *.o .*.swp *~ .tmp.o *.dep $(MYOBJS) $(MYDETS) $(TARGET_DEP) $(TARGET_LIB) $(MYLOGS)
	@for subdir in $(SUBDIRS); do (cd $$subdir; make clean SUBCOMPONENT=$$subdir;); done;
#clean:
#	@for subdir in $(SUBDIRS); do (cd $$subdir; make clean;); done;
